<?php 


class AjaxController extends Zend_Controller_Action
{

    public function init()
    {
        $this->_helper->layout->disableLayout();
        /* Initialize action controller here */
        $response = $this->getResponse();
        $response->setHeader('Content-Type', 'text/x-json');
    }

    function completeAction()
    {
        $query = $this->_request->getParam('q');
        $data = array(
            array('key' => 5, 'value' => 'test'),
            array('key' => 10, 'value' => 'za vdv')
        );

        //        $this->view->data = $data;
        //        $this->renderScript('/ajax/json.phtml');

    }

    function tagsAction()
    {
        $tag = $this->_request->getParam('tag');
        $data = array();

        //Ищем ID совпадений по названию тега в сфинксе.
        $searchManager = new \Managers\Search();
        $searchResult = $searchManager->getSearchTags($tag);

        if ($searchResult['total_found'] > 0) {
            //Получаем записи для автодополнения.
            $tagsManager = new \Managers\Tags();
            $data = $tagsManager->getByArray($searchResult['matches']);
        }

        $this->view->data = $data;
        $this->renderScript('/ajax/json.phtml');
    }

    public function rubricsAction()
    {
        $rubric = $this->_request->getParam('rubric');
        $rubricsManager = new \Managers\ItemsRubrics();

        $rubrics = $rubricsManager->getList($rubric);
        $this->view->data = $rubrics;
        $this->renderScript('/ajax/json.phtml');
    }


}
